// 切换暗黑主题
export function toDark(dark: boolean): void {
  console.log("运行dark-css::toDark");
  if (dark) {
    if (document.getElementById("dark-style")) {
      console.log("被退出");
      return;
    }
    const style = `
            html {
                background-color: rgb(255, 255, 255) !important;
                filter: invert(1) contrast(0.95) !important;
            }
            iframe {
                background-color: rgb(255, 255, 255) !important;
                filter: invert(1) contrast(0.95) !important;
            }
            img {
                filter: invert(1) contrast(0.95) !important;
            }
        `;
    const styleEl: HTMLStyleElement = document.createElement("style");
    console.log("运行styleEl 切换");
    styleEl.id = "dark-style";
    styleEl.textContent = style;
    document.head.append(styleEl);
  } else {
    const styleEl: HTMLElement | null = document.getElementById("dark-style");
    console.log("移除dark-style");
    if (styleEl) {
      styleEl.remove();
    }
  }
}
